package com.lan.model;

import com.lan.script.FunctionOt;
import com.lan.script.ScriptOt;

public final class Vv implements Value {

    private Symbol symbol;

    private ScriptOt object;

    public Vv(Symbol symbol, ScriptOt object) {
        this.symbol = symbol;
        this.object = object;
    }

    @Override
    public Object getValue() {
        return object.get(symbol);
    }

    @Override
    public void setValue(Object value) {
        object.add(symbol, value);
        //如果variable是函数型变量，那改变functionObject.receiver
        if (value instanceof FunctionOt) {
            ((FunctionOt) value).setRv(symbol);
        }
    }

    @Override
    public Symbol getSymbol() {
        return symbol;
    }


    @Override
    public ScriptOt get() {
        return object;
    }

    @Override
    public String toString() {
        return "Value of " + symbol.name + " : " + getValue();
    }
}
